﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
using System.Xml.Serialization;

namespace BuildSystem.MVC.Common
{
    public class Utility
    {
        public static string SerializeFormData(BuildFormData formSchema)
        {
            XmlSerializer ser = new XmlSerializer(formSchema.GetType());
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            System.IO.StringWriter writer = new System.IO.StringWriter(sb);
            ser.Serialize(writer, formSchema);
            return sb.ToString();
        }

        public static BuildFormData DeserializeFormDataXml(string schemaXml)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(schemaXml);
            XmlNodeReader reader = new XmlNodeReader(doc.DocumentElement);
            XmlSerializer ser = new XmlSerializer(typeof(BuildFormData));
            BuildFormData obj = ser.Deserialize(reader) as BuildFormData;
            return obj;
        }

        public static string SerializeFormSchema(BuildForm formSchema)
        {
            XmlSerializer ser = new XmlSerializer(formSchema.GetType());
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            System.IO.StringWriter writer = new System.IO.StringWriter(sb);
            ser.Serialize(writer, formSchema);
            return sb.ToString();
        }

        public static BuildForm DeserializeFormSchemaXml(string schemaXml)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(schemaXml);
            XmlNodeReader reader = new XmlNodeReader(doc.DocumentElement);
            XmlSerializer ser = new XmlSerializer(typeof(BuildForm));
            BuildForm obj = ser.Deserialize(reader) as BuildForm;
            return obj;
        }

        public static string SerializePnlDiv(div formSchema)
        {
            XmlSerializer ser = new XmlSerializer(formSchema.GetType());
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            System.IO.StringWriter writer = new System.IO.StringWriter(sb);
            ser.Serialize(writer, formSchema);
            return sb.ToString();
        }

        public static div DeserializePnlDevXml(string schemaXml)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(schemaXml);
            XmlNodeReader reader = new XmlNodeReader(doc.DocumentElement);
            XmlSerializer ser = new XmlSerializer(typeof(div));
            div obj = ser.Deserialize(reader) as div;
            return obj;
        }
    }
}